﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace TestApp.Flowchart.Model
{
    class ImageNode1 : FlowNode
    {
        private string _imagePath;
        [JsonProperty]
        public string ImagePath
        {
            get { return _imagePath; }
            set
            {
                _imagePath = value;
                OnPropertyChanged("ImagePath");
            }
        }

        public ImageNode1() { }
        
        public override FrameworkElement CreateContent()
        {
            var textBlock = base.CreateContent() as TextBlock;

            var canvas = new Canvas();

            var ui = new Border();

            ImageBrush b = new ImageBrush();
            b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Resources/imagenode1.png", UriKind.Absolute));
            b.Stretch = Stretch.Fill;
            ui.Background = b;
            ui.Width = this.Width;
            ui.Height = this.Height;

            canvas.Children.Add(ui);


            Canvas.SetLeft(textBlock, this.Width / 2);
            Canvas.SetTop(textBlock, this.Height + 10);

            canvas.Children.Add(textBlock);

            return canvas;
        }

        public FlowNode Json2Obj(string value)
        {
            return JSONUtils.Json2Obj<ImageNode1>(value);
        }        
    }
}
